<?php
/**
 * Created by PhpStorm.
 * User: zyh
 * Date: 2018/5/3
 * Time: 下午6:54
 */

namespace app\index\command;
use GatewayWorker\BusinessWorker;
use GatewayWorker\Gateway;
use GatewayWorker\Register;
use think\console\Command;
use think\console\Input;
use think\console\input\Argument;
use think\console\Output;
use Workerman\Worker;

class workman extends Command
{

    public function __construct($name = null)
    {
        parent::__construct($name);


        if(strpos(strtolower(PHP_OS), 'win') === 0)
        {
            exit("Only Run at linux/unix \n");
        }

        // 检查扩展
        if(!extension_loaded('pcntl'))
        {
            exit("Please install pcntl extension. See http://doc3.workerman.net/appendices/install-extension.html\n");
        }

        if(!extension_loaded('posix'))
        {
            exit("Please install posix extension. See http://doc3.workerman.net/appendices/install-extension.html\n");
        }
    }

    protected function configure()
    {
        $this->setName("workman");
        $this->addArgument("oper",Argument::REQUIRED,"start?");
    }

    protected function execute(Input $input, Output $output)
    {

        //注册服务
        $register = new Register('text://0.0.0.0:1236');

        //网关服务
        $gateway = new Gateway("websocket://0.0.0.0:8282");
        $gateway->name = "Gateway";
        $gateway->count = 4;
        $gateway->lanIp = "127.0.0.1";
        $gateway->startPort = 7500;
        $gateway->registerAddress = "127.0.0.1:1236";
//        $gateway->pingInterval = 5;
//        $gateway->pingData = '{"type":"ping"}';

        //业务服务
        $worker = new BusinessWorker();
        $worker->name = "BusinessWorker";
        $worker->count = 4;
        $worker->registerAddress = '127.0.0.1:1236';
        $worker->eventHandler = 'app\index\command\Events';

        Worker::runAll();
    }


}